home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-10-25 | 15.8 KB | 1,493 lines |
- # 1 "unlzh.c"
-
-
-
-
-
-
-
-
-
- # 1 "/usr/include/stdio.h" 1 3
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- # 1 "/usr/include/sys/cdefs.h" 1 3
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- # 82 "/usr/include/sys/cdefs.h" 3
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- # 43 "/usr/include/stdio.h" 2 3
-
-
- # 1 "/usr/include/machine/ansi.h" 1 3
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- # 45 "/usr/include/stdio.h" 2 3
-
-
- typedef unsigned int size_t;
-
-
-
-
-
-
-
- typedef long fpos_t;
-
-
-
-
-
-
-
-
-
-
- struct __sbuf {
- unsigned char *_base;
- int _size;
- };
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- typedef struct __sFILE {
- unsigned char *_p;
- int _r;
- int _w;
- short _flags;
- short _file;
- struct __sbuf _bf;
- int _lbfsize;
-
-
- void *_cookie;
- int (*_close) (void *) ;
- int (*_read) (void *, char *, int) ;
- fpos_t (*_seek) (void *, fpos_t, int) ;
- int (*_write) (void *, const char *, int) ;
-
-
- struct __sbuf _ub;
- unsigned char *_up;
- int _ur;
-
-
- unsigned char _ubuf[3];
- unsigned char _nbuf[1];
-
-
- struct __sbuf _lb;
-
-
- int _blksize;
- int _offset;
- } FILE;
-
-
- extern FILE __sF[];
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- void clearerr (FILE *) ;
- int fclose (FILE *) ;
- int feof (FILE *) ;
- int ferror (FILE *) ;
- int fflush (FILE *) ;
- int fgetc (FILE *) ;
- int fgetpos (FILE *, fpos_t *) ;
- char *fgets (char *, size_t, FILE *) ;
- FILE *fopen (const char *, const char *) ;
- int fprintf (FILE *, const char *, ...) ;
- int fputc (int, FILE *) ;
- int fputs (const char *, FILE *) ;
- size_t fread (void *, size_t, size_t, FILE *) ;
- FILE *freopen (const char *, const char *, FILE *) ;
- int fscanf (FILE *, const char *, ...) ;
- int fseek (FILE *, long, int) ;
- int fsetpos (FILE *, const fpos_t *) ;
- long ftell (const FILE *) ;
- size_t fwrite (const void *, size_t, size_t, FILE *) ;
- int getc (FILE *) ;
- int getchar (void) ;
- char *gets (char *) ;
-
- extern int sys_nerr;
- extern const char *const sys_errlist[];
-
- void perror (const char *) ;
- int printf (const char *, ...) ;
- int putc (int, FILE *) ;
- int putchar (int) ;
- int puts (const char *) ;
- int remove (const char *) ;
- int rename (const char *, const char *) ;
- void rewind (FILE *) ;
- int scanf (const char *, ...) ;
- void setbuf (FILE *, char *) ;
- int setvbuf (FILE *, char *, int, size_t) ;
- int sprintf (char *, const char *, ...) ;
- int sscanf (const char *, const char *, ...) ;
- FILE *tmpfile (void) ;
- char *tmpnam (char *) ;
- int ungetc (int, FILE *) ;
- int vfprintf (FILE *, const char *, char * ) ;
- int vprintf (const char *, char * ) ;
- int vsprintf (char *, const char *, char * ) ;
-
-
-
-
-
-
-
-
-
-
- char *ctermid (char *) ;
- char *cuserid (char *) ;
- FILE *fdopen (int, const char *) ;
- int fileno (FILE *) ;
-
-
-
-
-
-
-
-
- char *fgetline (FILE *, size_t *) ;
- int fpurge (FILE *) ;
- int getw (FILE *) ;
- int pclose (FILE *) ;
- FILE *popen (const char *, const char *) ;
- int putw (int, FILE *) ;
- void setbuffer (FILE *, char *, int) ;
- int setlinebuf (FILE *) ;
- char *tempnam (const char *, const char *) ;
- int snprintf (char *, size_t, const char *, ...)
- __attribute__((format (printf, 3, 4)));
- int vsnprintf (char *, size_t, const char *, char * )
- __attribute__((format (printf, 3, 0)));
- int vscanf (const char *, char * )
- __attribute__((format (scanf, 1, 0)));
- int vsscanf (const char *, const char *, char * )
- __attribute__((format (scanf, 2, 0)));
-
-
-
-
-
-
-
-
-
-
-
-
-
- FILE *funopen (const void *,
- int (*)(void *, char *, int),
- int (*)(void *, const char *, int),
- fpos_t (*)(void *, fpos_t, int),
- int (*)(void *)) ;
-
-
-
-
-
-
-
-
-
- int __srget (FILE *) ;
- int __svfscanf (FILE *, const char *, char * ) ;
- int __swbuf (int, FILE *) ;
-
-
-
-
-
-
-
-
- static __inline int __sputc(int _c, FILE *_p) {
- if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
- return (*_p->_p++ = _c);
- else
- return (__swbuf(_c, _p));
- }
- # 337 "/usr/include/stdio.h" 3
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- # 10 "unlzh.c" 2
-
-
- # 1 "tailor.h" 1
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- # 65 "tailor.h"
-
-
-
-
- # 109 "tailor.h"
-
-
- # 130 "tailor.h"
-
-
- # 144 "tailor.h"
-
-
-
-
-
-
-
-
-
- # 172 "tailor.h"
-
-
- # 194 "tailor.h"
-
-
- # 215 "tailor.h"
-
-
- # 230 "tailor.h"
-
-
- # 250 "tailor.h"
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- # 12 "unlzh.c" 2
-
- # 1 "gzip.h" 1
-
-
-
-
-
-
-
-
-
-
-
-
-
- typedef void *voidp;
-
-
-
-
-
-
-
-
-
- # 1 "/usr/include/string.h" 1 3
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- void *memchr (const void *, int, size_t) ;
-
-
-
-
- void *memmove (void *, const void *, size_t) ;
- void *memset (void *, int, size_t) ;
- char *strcat (char *, const char *) ;
- char *strchr (const char *, int) ;
- int strcmp (const char *, const char *) ;
- int strcoll (const char *, const char *) ;
- char *strcpy (char *, const char *) ;
- size_t strcspn (const char *, const char *) ;
- char *strerror (int) ;
- size_t strlen (const char *) ;
- char *strncat (char *, const char *, size_t) ;
- int strncmp (const char *, const char *, size_t) ;
- char *strncpy (char *, const char *, size_t) ;
- char *strpbrk (const char *, const char *) ;
- char *strrchr (const char *, int) ;
- size_t strspn (const char *, const char *) ;
- char *strstr (const char *, const char *) ;
- char *strtok (char *, const char *) ;
- size_t strxfrm (char *, const char *, size_t) ;
-
-
-
- int bcmp (const void *, const void *, size_t) ;
- void bcopy (const void *, void *, size_t) ;
- void bzero (void *, size_t) ;
- int ffs (int) ;
- char *index (const char *, int) ;
- void *memccpy (void *, const void *, int, size_t) ;
- char *rindex (const char *, int) ;
- int strcasecmp (const char *, const char *) ;
- char *strdup (const char *) ;
- void strmode (int, char *) ;
- int strncasecmp (const char *, const char *, size_t) ;
- char *strsep (char **, const char *) ;
- void swab (const void *, void *, size_t) ;
-
-
-
-
- # 24 "gzip.h" 2
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- typedef unsigned char uch;
- typedef unsigned short ush;
- typedef unsigned long ulg;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- extern int method;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- # 108 "gzip.h"
-
-
-
-
-
-
-
- extern uch inbuf [] ;
- extern uch outbuf [] ;
- extern ush d_buf [] ;
- extern uch window [] ;
-
-
-
-
- extern ush prev [] ;
-
-
-
-
-
-
-
- extern unsigned insize;
- extern unsigned inptr;
- extern unsigned outcnt;
-
- extern long bytes_in;
- extern long bytes_out;
- extern long header_bytes;
-
-
-
-
- extern int ifd;
- extern int ofd;
- extern char ifname[];
- extern char ofname[];
- extern char *progname;
-
- extern long time_stamp;
- extern long ifile_size;
-
- typedef int file_t;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- extern int decrypt;
- extern int exit_code;
- extern int verbose;
- extern int quiet;
- extern int level;
- extern int test;
- extern int to_stdout;
- extern int save_orig_name;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- # 225 "gzip.h"
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- extern int zip (int in, int out) ;
- extern int file_read (char *buf, unsigned size) ;
-
-
- extern int unzip (int in, int out) ;
- extern int check_zipfile (int in) ;
-
-
- extern int unpack (int in, int out) ;
-
-
- extern int unlzh (int in, int out) ;
-
-
- void abort_gzip (void) ;
-
-
- void lm_init (int pack_level, ush *flags) ;
- ulg deflate (void) ;
-
-
- void ct_init (ush *attr, int *method) ;
- int ct_tally (int dist, int lc) ;
- ulg flush_block (char *buf, ulg stored_len, int eof) ;
-
-
- void bi_init (file_t zipfile) ;
- void send_bits (int value, int length) ;
- unsigned bi_reverse (unsigned value, int length) ;
- void bi_windup (void) ;
- void copy_block (char *buf, unsigned len, int header) ;
- extern int (*read_buf) (char *buf, unsigned size) ;
-
-
- extern int copy (int in, int out) ;
- extern ulg updcrc (uch *s, unsigned n) ;
- extern void clear_bufs (void) ;
- extern int fill_inbuf (int eof_ok) ;
- extern void flush_outbuf (void) ;
- extern void flush_window (void) ;
- extern void write_buf (int fd, voidp buf, unsigned cnt) ;
- extern char *strlwr (char *s) ;
- extern char *basename (char *fname) ;
- extern void make_simple_name (char *name) ;
- extern char *add_envopt (int *argcp, char ***argvp, char *env) ;
- extern void error (char *m) ;
- extern void warn (char *a, char *b) ;
- extern void read_error (void) ;
- extern void write_error (void) ;
- extern void display_ratio (long num, long den, FILE *file) ;
- extern voidp xmalloc (unsigned int size) ;
-
-
- extern int inflate (void) ;
- # 13 "unlzh.c" 2
-
- # 1 "lzw.h" 1
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- extern int maxbits;
- extern int block_mode;
-
- extern int lzw (int in, int out) ;
- extern int unlzw (int in, int out) ;
- # 14 "unlzh.c" 2
-
-
-
-
- static unsigned decode (unsigned count, uch buffer[]) ;
- static void decode_start (void) ;
-
-
- static void huf_decode_start (void) ;
- static unsigned decode_c (void) ;
- static unsigned decode_p (void) ;
- static void read_pt_len (int nn, int nbit, int i_special) ;
- static void read_c_len (void) ;
-
-
- static void fillbuf (int n) ;
- static unsigned getbits (int n) ;
- static void init_getbits (void) ;
-
-
-
- static void make_table (int nchar, uch bitlen[],
- int tablebits, ush table[]) ;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- static uch pt_len[( 16 + 3) ];
- static unsigned blocksize;
- static ush pt_table[256];
-
-
-
-
-
-
-
-
-
-
-
- static ush bitbuf;
- static unsigned subbitbuf;
- static int bitcount;
-
- static void fillbuf(n)
- int n;
- {
- bitbuf <<= n;
- while (n > bitcount) {
- bitbuf |= subbitbuf << (n -= bitcount);
- subbitbuf = (unsigned) (inptr < insize ? inbuf[inptr++] : fill_inbuf(1)) ;
- if ((int)subbitbuf == (-1) ) subbitbuf = 0;
- bitcount = 8 ;
- }
- bitbuf |= subbitbuf >> (bitcount -= n);
- }
-
- static unsigned getbits(n)
- int n;
- {
- unsigned x;
-
- x = bitbuf >> ((8 * 2 * sizeof(char)) - n); fillbuf(n);
- return x;
- }
-
- static void init_getbits()
- {
- bitbuf = 0; subbitbuf = 0; bitcount = 0;
- fillbuf((8 * 2 * sizeof(char)) );
- }
-
-
-
-
-
- static void make_table(nchar, bitlen, tablebits, table)
- int nchar;
- uch bitlen[];
- int tablebits;
- ush table[];
- {
- ush count[17], weight[17], start[18], *p;
- unsigned i, k, len, ch, jutbits, avail, nextcode, mask;
-
- for (i = 1; i <= 16; i++) count[i] = 0;
- for (i = 0; i < (unsigned)nchar; i++) count[bitlen[i]]++;
-
- start[1] = 0;
- for (i = 1; i <= 16; i++)
- start[i + 1] = start[i] + (count[i] << (16 - i));
- if ((start[17] & 0xffff) != 0)
- error("Bad table\n");
-
- jutbits = 16 - tablebits;
- for (i = 1; i <= (unsigned)tablebits; i++) {
- start[i] >>= jutbits;
- weight[i] = (unsigned) 1 << (tablebits - i);
- }
- while (i <= 16) {
- weight[i] = (unsigned) 1 << (16 - i);
- i++;
- }
-
- i = start[tablebits + 1] >> jutbits;
- if (i != 0) {
- k = 1 << tablebits;
- while (i != k) table[i++] = 0;
- }
-
- avail = nchar;
- mask = (unsigned) 1 << (15 - tablebits);
- for (ch = 0; ch < (unsigned)nchar; ch++) {
- if ((len = bitlen[ch]) == 0) continue;
- nextcode = start[len] + weight[len];
- if (len <= (unsigned)tablebits) {
- for (i = start[len]; i < nextcode; i++) table[i] = ch;
- } else {
- k = start[len];
- p = &table[k >> jutbits];
- i = len - tablebits;
- while (i != 0) {
- if (*p == 0) {
- (prev+0x8000 ) [avail] = prev [avail] = 0;
- *p = avail++;
- }
- if (k & mask) p = &(prev+0x8000 ) [*p];
- else p = & prev [*p];
- k <<= 1; i--;
- }
- *p = ch;
- }
- start[len] = nextcode;
- }
- }
-
-
-
-
-
- static void read_pt_len(nn, nbit, i_special)
- int nn;
- int nbit;
- int i_special;
- {
- int i, c, n;
- unsigned mask;
-
- n = getbits(nbit);
- if (n == 0) {
- c = getbits(nbit);
- for (i = 0; i < nn; i++) pt_len[i] = 0;
- for (i = 0; i < 256; i++) pt_table[i] = c;
- } else {
- i = 0;
- while (i < n) {
- c = bitbuf >> ((8 * 2 * sizeof(char)) - 3);
- if (c == 7) {
- mask = (unsigned) 1 << ((8 * 2 * sizeof(char)) - 1 - 3);
- while (mask & bitbuf) { mask >>= 1; c++; }
- }
- fillbuf((c < 7) ? 3 : c - 3);
- pt_len[i++] = c;
- if (i == i_special) {
- c = getbits(2);
- while (--c >= 0) pt_len[i++] = 0;
- }
- }
- while (i < nn) pt_len[i++] = 0;
- make_table(nn, pt_len, 8, pt_table);
- }
- }
-
- static void read_c_len()
- {
- int i, c, n;
- unsigned mask;
-
- n = getbits(9 );
- if (n == 0) {
- c = getbits(9 );
- for (i = 0; i < (255 + 256 + 2 - 3 ) ; i++) outbuf [i] = 0;
- for (i = 0; i < 4096; i++) d_buf [i] = c;
- } else {
- i = 0;
- while (i < n) {
- c = pt_table[bitbuf >> ((8 * 2 * sizeof(char)) - 8)];
- if (c >= ( 16 + 3) ) {
- mask = (unsigned) 1 << ((8 * 2 * sizeof(char)) - 1 - 8);
- do {
- if (bitbuf & mask) c = (prev+0x8000 ) [c];
- else c = prev [c];
- mask >>= 1;
- } while (c >= ( 16 + 3) );
- }
- fillbuf((int) pt_len[c]);
- if (c <= 2) {
- if (c == 0) c = 1;
- else if (c == 1) c = getbits(4) + 3;
- else c = getbits(9 ) + 20;
- while (--c >= 0) outbuf [i++] = 0;
- } else outbuf [i++] = c - 2;
- }
- while (i < (255 + 256 + 2 - 3 ) ) outbuf [i++] = 0;
- make_table((255 + 256 + 2 - 3 ) , outbuf , 12, d_buf );
- }
- }
-
- static unsigned decode_c()
- {
- unsigned j, mask;
-
- if (blocksize == 0) {
- blocksize = getbits(16);
- if (blocksize == 0) {
- return (255 + 256 + 2 - 3 ) ;
- }
- read_pt_len(( 16 + 3) , 5 , 3);
- read_c_len();
- read_pt_len(( 13 + 1) , 4 , -1);
- }
- blocksize--;
- j = d_buf [bitbuf >> ((8 * 2 * sizeof(char)) - 12)];
- if (j >= (255 + 256 + 2 - 3 ) ) {
- mask = (unsigned) 1 << ((8 * 2 * sizeof(char)) - 1 - 12);
- do {
- if (bitbuf & mask) j = (prev+0x8000 ) [j];
- else j = prev [j];
- mask >>= 1;
- } while (j >= (255 + 256 + 2 - 3 ) );
- }
- fillbuf((int) outbuf [j]);
- return j;
- }
-
- static unsigned decode_p()
- {
- unsigned j, mask;
-
- j = pt_table[bitbuf >> ((8 * 2 * sizeof(char)) - 8)];
- if (j >= ( 13 + 1) ) {
- mask = (unsigned) 1 << ((8 * 2 * sizeof(char)) - 1 - 8);
- do {
- if (bitbuf & mask) j = (prev+0x8000 ) [j];
- else j = prev [j];
- mask >>= 1;
- } while (j >= ( 13 + 1) );
- }
- fillbuf((int) pt_len[j]);
- if (j != 0) j = ((unsigned) 1 << (j - 1)) + getbits((int) (j - 1));
- return j;
- }
-
- static void huf_decode_start()
- {
- init_getbits(); blocksize = 0;
- }
-
-
-
-
-
- static int j;
- static int done;
-
- static void decode_start()
- {
- huf_decode_start();
- j = 0;
- done = 0;
- }
-
-
-
- static unsigned decode(count, buffer)
- unsigned count;
- uch buffer[];
-
-
-
-
-
-
-
-
- {
- static unsigned i;
- unsigned r, c;
-
- r = 0;
- while (--j >= 0) {
- buffer[r] = buffer[i];
- i = (i + 1) & (((unsigned) 1 << 13 ) - 1);
- if (++r == count) return r;
- }
- for ( ; ; ) {
- c = decode_c();
- if (c == (255 + 256 + 2 - 3 ) ) {
- done = 1;
- return r;
- }
- if (c <= 255 ) {
- buffer[r] = c;
- if (++r == count) return r;
- } else {
- j = c - (255 + 1 - 3 );
- i = (r - decode_p() - 1) & (((unsigned) 1 << 13 ) - 1);
- while (--j >= 0) {
- buffer[r] = buffer[i];
- i = (i + 1) & (((unsigned) 1 << 13 ) - 1);
- if (++r == count) return r;
- }
- }
- }
- }
-
-
-
-
-
- int unlzh(in, out)
- int in;
- int out;
- {
- unsigned n;
- ifd = in;
- ofd = out;
-
- decode_start();
- while (!done) {
- n = decode((unsigned) ((unsigned) 1 << 13 ) , window);
- if (!test && n > 0) {
- write_buf(out, (char*)window, n);
- }
- }
- return 0 ;
- }
-